import { Session } from "mydog";
import { RoomMgr } from "../../../app/svr_game/roomMgr";
import { svr_game } from "../../../app/svr_game/svr_game";
import { getGameState } from "../../../app/util/gameUtil";
import { e_sort_out_type } from "../../../app/util/someInterface";


export default class Handler {
    private roomMgr: RoomMgr;
    constructor() {
        this.roomMgr = svr_game.roomMgr;
    }

    // 抢主 （定义这局的软主的花色）
    setMasterColor(msg: { "color": number }, session: Session, next: Function) {
        let room = this.roomMgr.getRoom(getGameState(session).roomId);
        room.setMasterColor(session.uid, msg.color);
    }

    // 底牌弄到玩家手里
    addCardToUser(msg: { "id": number }, session: Session, next: Function) {
        let room = this.roomMgr.getRoom(getGameState(session).roomId);
        room.addCardToUser(session.uid, msg.id);
    }

    // 客家话  叠牌 其实就是 这轮的庄家整理牌的过程
    sortOutCards(msg: { "ids": number[], action: e_sort_out_type }, session: Session, next: Function) {
        let room = this.roomMgr.getRoom(getGameState(session).roomId);
        room.sortOutCards(session.uid, msg.ids, msg.action);
    }

    // 抢地主
    qiangDizhu(msg: { "score": number }, session: Session, next: Function) {
        let room = this.roomMgr.getRoom(getGameState(session).roomId);
        room.qiangDizhu(session.uid, msg.score);
    }
    // 出牌
    playCard(msg: { "ids": number[] }, session: Session, next: Function) {
        let room = this.roomMgr.getRoom(getGameState(session).roomId);
        room.playCard(session.uid, msg.ids, next);
    }

    // 离开
    leave(msg: any, session: Session, next: Function) {
        let room = this.roomMgr.getRoom(getGameState(session).roomId);
        room.leave(session.uid);
    }
}